package com.hnhcyy.goods.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hnhcyy.goods.mapper.BannerMapper;
import com.hnhcyy.goods.mapper.GoodsMapper;
import com.hnhcyy.goods.pojo.Banner;
import com.hnhcyy.goods.pojo.BannerSp;
import com.hnhcyy.goods.pojo.GoodsQueryParam;
import com.hnhcyy.goods.service.BannerService;


@Service
public class BannerServiceImpl implements BannerService {
	
	@Autowired
	private BannerMapper bannerMapper;
	@Autowired
	private GoodsMapper goodsMapper;

	@Override
	public List<Banner> getList(String devicetype, int sjid, String dwbh, boolean appointGoods) {
		// 查出所有轮播图
		List<Banner> bannerList = bannerMapper.selectListById(devicetype, sjid);
		if(StringUtils.isBlank(dwbh)) {
			//未登录时，返回所有内容
			return bannerList;
		}
		// 登录后，根据轮播图里面的商品控销到客户
		int size = bannerList.size();
		for(int i = 0; i < size; i++) {
			Banner banner = bannerList.get(i);
			List<BannerSp> bannerSplist = banner.getBannerSpList();
			for(BannerSp bannerSp : bannerSplist) {
//				int count = spkfkMapper.getKxspCount(sjid, dwbh, bannerSp.getSpid(),spMchkEnableCount);
				// 判断商品是否可销
				GoodsQueryParam queryParam = new GoodsQueryParam(bannerSp.getSpid(), dwbh, sjid, appointGoods);
				int count = goodsMapper.selectOneGoodsIsSell(queryParam);
				if(count == 0) {
					// 如果不可销，则移除当前的banner图
					bannerList.remove(banner);
					i--;
					size--;
					break;
				}
			}
		}
		return bannerList;
	}

}
